package ltk.servlet;


import hezi.common.KeyTool;
import hezi.common.SettingInDB;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.Template;

import dz.common.PropTool;

public class ServerpanelServlet extends BaseServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);
		defaultpage(request);
	}
	


	private void defaultpage(HttpServletRequest request) {
		Template t = ve.getTemplate("serverpanel.html");
		
		String uid = SettingInDB.getValue("uid");
		logger.info("uid: " + uid);

		String queue = KeyTool.getQueue(uid);
		logger.info("queue: " + queue);
		
		String key = KeyTool.getKey(uid);
		logger.info("key: " + key);
		
		
		context.put("targetqueueid", queue);
		context.put("targetkey", key);
		
		logger.info(uid);
		fillContext();
		writeout(t);
	}

	private void fillContext() {
		context.put("skiploadpost",PropTool.getString("skiploadpost"));	
		context.put("fackdownload",PropTool.getString("fackdownload"));
		
		context.put("downloadevenexist",PropTool.getString("downloadevenexist"));	
		context.put("scanthread",PropTool.getInt("scanthread"));	
				
		context.put("col",PropTool.getString("col"));	
		context.put("limit",PropTool.getString("limit"));	
		
		context.put("btgcurl",PropTool.getString("btgcurl"));	
		context.put("aisexurl",PropTool.getString("aisexurl"));	
		
		context.put("avurl",PropTool.getString("avurl"));	
		context.put("clurl",PropTool.getString("clurl"));	
		
		context.put("listpagestartindex",PropTool.getString("listpagestartindex"));
		context.put("listpagestopindex",PropTool.getString("listpagestopindex"));	
		
		context.put("lastvisitforum",PropTool.getString("lastvisitforum"));	
		context.put("lastvisitforumgroup",PropTool.getString("lastvisitforumgroup"));	
		
		context.put("trstartindex",PropTool.getString("trstartindex"));	
		context.put("trstopindex",PropTool.getString("trstopindex"));	
		context.put("trnum",PropTool.getString("trnum"));	
		context.put("droptable",PropTool.getString("droptable"));	
		
		context.put("nostoredb",PropTool.getString("nostoredb"));	
		
	}
	
	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		super.doPost(request, response);
		
		String action = request.getParameter("action");
		logger.info("aciton:" + action);
		if(action.equals("update")){
			String id = request.getParameter("id");
			String newvalue = request.getParameter("newvalue");
			PropTool.updateProperty(id, newvalue);
			logger.info(id+"="+newvalue);
			writeout("OK");
		}
	}
}
